#include<vector>
#include<algorithm>
using namespace std;

vector<vector<int>> threeSum(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    vector<vector<int>> vv;
    for (int i = 0; i < nums.size() - 2; i++)
    {
        if (nums[i] > 0) break;
        if (i > 0 && nums[i] == nums[i - 1]) continue;
        int left = i + 1, right = nums.size() - 1;
        while (left < right)
        {
            if (nums[left] + nums[right] == -nums[i])
            {
                vv.insert(vv.end(), { nums[i], nums[left], nums[right] });
                left++;
                right--;
                while (left < nums.size() && nums[left] == nums[left - 1])
                    left++;
                while (right > i && nums[right] == nums[right + 1])
                    right--;
            }
            else if (nums[left] + nums[right] < -nums[i]) left++;
            else right--;
        }
    }
    return vv;
}

int main()
{
    vector<vector<int>> vv;
	//vv.push_back({});
	//vv.back().insert(vv.back().end(), {1,2,3});
	vv.insert(vv.end(), { 1,2,3 });
	vv.insert(vv.end(), { 1,2,3 });
    vector<int> v{ 0,0,0 };
    threeSum(v);

	return 0;
}